<?
/**
 *会员类.
 *调用成员函数获取登录会员相关信息
 */
class MemberTicketMachine{
    public function __construct($s,$memberID){
        if (!$memberID || !is_numeric($memberID)) {
            throw new ErrorException('用户ID为空！');
        }
        $this->fid=$this->memberID = $memberID;
        $this->m_info=$GLOBALS['le']->fetch_assoc();
        $this->s=$s;
    }
    /**
     * 查询会员可分销产品信息
     *
     * @param null $lid  景区id，默认不传，传入只返回改景区产品
     * @param bool $include_evolute 发起转供应，二级域名店铺需要此参数为false
     * @param bool $include_second  是否获取转分销的产品，默认获取；取票机的目前只获取直销的产品（added at 2015年7月13日10:47:44）
     * @return array 会员可分销产品，含直接供应和转供应产品
     */
    public function salePros($lid=null, $include_evolute=true, $include_second=true, $saler_id=array())
    {

        $r=array();
//
        $sql=<<<SQL
select p.id as pid,p.apply_did,p.p_status,l.id as lid,l.p_type,l.areacode,
l.title,l.salerid,l.area,l.topic,l.px,l.runtime,l.terminal,l.imgpath,
l.address,t.id as tid,t.pay,t.getaddr,t.title as ttitle,t.tprice,t.notes,
t.buy_limit_low,t.ddays,t.delaydays,t.status,f.ass_station,f.tourist_info,
f.mdays,f.mhour,f.rdays,t.order_end,t.order_start,t.delaytype,t.sync_status
from uu_products p left join uu_land l on p.contact_id=l.id left join
uu_jq_ticket t on p.id=t.pid left join uu_land_f f on f.pid=p.id
SQL;
        if (count($saler_id)>0) {
            $filter = "l.salerid IN(".implode(',', $saler_id).")";
        } else {
            $filter = "p.apply_did={$this->fid}";
        }
        $where="where $filter AND p.p_status=0 and p.apply_limit=1";
        if($lid) $where.=" and l.id=$lid ";
        $orderby=" order by l.px desc ";
        $salePids = array();
        $str1 ="$sql $where $orderby";
//        echo $str1;
        $GLOBALS['le']->query($str1);
        while($row=$GLOBALS['le']->fetch_assoc()){
//            if($row['apply_did']!=$this->fid
//                &&$salePids[$row['apply_did']][0]!="A"
//                &&!in_array($row['pid'],$salePids[$row['apply_did']]))
//            {
//                continue;
//            }
            $row['sapply_did']=$row['apply_did'];
            $row['aid']=0;
            $row['lvl']=0;
            $r[]=$row;
        }
        return $r;
    }
}
?>